package Code.Menu.View;

import org.jrabbit.base.graphics.transforms.Vector2d;
import org.jrabbit.base.managers.window.WindowManager;
import org.jrabbit.standard.game.graphics.skins.image.ImageSkin;
import org.jrabbit.standard.game.objects.base.BaseSprite;
import org.lwjgl.opengl.GL11;

public class Stars extends BaseSprite
{
	private ImageSkin skin;

	private float baseX;
	private float baseY;
	private float startX;
	private float startY;
	private float iterationsX;
	private float iterationsY;
	
	public Stars()
	{
		skin = new ImageSkin("Resources/Images/Menu/Stars.png");
		useScreenCoords(true);
		iterationsX = (float) (WindowManager.getDisplayWidth() / getWidth());
		iterationsY = (float) (WindowManager.getDisplayHeight() / getHeight());
	}
	
	public void adjustView(int delta, Vector2d offset)
	{
		baseX += delta * 0.000005f;
		baseY += delta * 0.000001f;
		startX = baseX + (float) (offset.x() / 3000);
		startY = baseY + (float) (offset.y() / 3000);
	}

	public void draw()
	{
		skin.object().bind();
		
		GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
		
		GL11.glTexCoord2f(startX, startY);
		GL11.glVertex2f(0, 0);
		GL11.glTexCoord2f(startX + iterationsX, startY);
		GL11.glVertex2f(WindowManager.getDisplayWidth(), 0);
		GL11.glTexCoord2f(startX, startY + iterationsY);
		GL11.glVertex2f(0, WindowManager.getDisplayHeight());
		GL11.glTexCoord2f(startX + iterationsX, startY + iterationsY);
		GL11.glVertex2f(WindowManager.getDisplayWidth(), WindowManager.getDisplayHeight());
		
		GL11.glEnd();
	}

	public double getWidth()
	{
		return skin.width();
	}

	public double getHeight()
	{
		return skin.height();
	}

}
